﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Dapper.Moon
{
    public class UnitOfWork : IUnitOfWork
    {
        public IDapperMoon Context { get; private set; }
        public IsolationLevel IsolationLevel { get; set; }

        public UnitOfWork(IDapperMoon context)
        {
            this.Context = context;
        }

        public void Begin()
        {
            Context.BeginTransaction(IsolationLevel);
        }

        public void Commit()
        {
            Context.CommitTransaction();
        }

        public void Rollback()
        {
            Context.RollbackTransaction();
        }

        ~UnitOfWork() => this.Dispose();

        public void Dispose()
        {
            Context.Dispose();
        }
    }
}
